<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>4_v-for绑定函数</title>
</head>

<body>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <div id="Application">
        <ul>
            <li v-for="item in 10" :ref="(el)=>{setItemRefs(el,item)}">
                {{item}}
            </li>
        </ul>
    </div>
    <script>
        const App = Vue.createApp({
            setup() {
                let itemRefs = Vue.ref([])
                const setItemRefs = (el, item) => {
                    if (el) {
                        itemRefs.value.push({
                            id: item,
                            el,
                        })
                    }
                };
                Vue.onMounted(() => {
                    console.log("打印itemRefs：", itemRefs.value)
                })

                return {
                    setItemRefs
                };
            },
        });
        App.mount("#Application");
    </script>
</body>

</html>